<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/socket.io/2.1.1/socket.io.js"></script>
</head>
<body>
    <script>
    //创建socket
    var socket = io('http://localhost:9092');//用于连接后端的服务
    /*
    创建自定义事件 'news'
    作用：接受服务端 socket.emit('news', 数据); 发出的数据
    */
    socket.on('connect', function () {
        socket.emit('text', JSON.stringify({userName:"caiyy",passWord:"123456"}));
    });
    socket.on('text1', function (data) {
        //输出服务端响应了数据
        console.log(data);
    });
    </script>
</body>
</html>